import java.lang.reflect.Array;
import java.util.Arrays;

public class 最强祝福力场 {
    public static int fieldOfGreatestBlessing(int[][] forceField) {
        //初始化变量, 创建离散化的数组
        int n = forceField.length;
        long[] xs = new long[2 * n];
        long[] ys = new long[2 * n];
        int k = 0;
        int p = 0;
        for (int i = 0; i < n; i++) {
            long x = forceField[i][0];
            long y = forceField[i][1];
            long r = forceField[i][2];
            //进行离散化
            xs[k++] = 2 * x - r;
            xs[k++] = 2 * x + r;
            ys[p++] = 2 * y - r;
            ys[p++] = 2 * y + r;
        }
        //排序加去重, 来对应原数组中的位置
        int sizex = sort(xs);
        int sizey = sort(ys);
        int[][] diff = new int[sizex + 2][sizey + 2];
        for (int i = 0; i < n; i++) {
            //寻找映射关系,通过下标来进行对应
            long x = forceField[i][0];
            long y = forceField[i][1];
            long r = forceField[i][2];
            int a = rank(xs,sizex,2 * x - r);
            int b = rank(ys,sizey,2 * y - r);
            int c = rank(xs,sizex,2 * x + r);
            int d = rank(ys,sizey,2 * y + r);
            //填写差分的信息
            set(a,b,c,d,diff);
        }
        int ret = -1;
        for (int i = 1; i <= sizex; i++) {
            for (int j = 1; j <= sizey; j++) {
                diff[i][j] += diff[i - 1][j] + diff[i][j - 1] - diff[i - 1][j - 1];
                ret = Math.max(ret,diff[i][j]);
            }
        }
        return ret;
    }

    private static void set(int a, int b, int c, int d, int[][] arr) {
        arr[a][b] += 1;
        arr[a][d + 1] -= 1;
        arr[c + 1][b] -= 1;
        arr[c + 1][d + 1] += 1;

    }

    private static int rank(long[] xs, int sizex, long i) {
        int left = 0;
        int right = sizex - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(xs[mid] < i){
                left = mid + 1;
            }else if(xs[mid] > i){
                right = mid - 1;
            }else {
                return mid + 1;
            }
        }
        //找不到
        return -1;
    }

    private static int sort(long[] xs) {
        int size = 1;
        Arrays.sort(xs);
        for (int i = 1; i < xs.length; i++) {
            if(xs[i] != xs[size - 1]){
                xs[size++] = xs[i];
            }
        }
        return size;
    }
    public static void main(String[] args) {
        fieldOfGreatestBlessing(new int[][]{{0,0,1},{1,0,1}});
    }
}
